package com.yygo.service;

import com.yygo.configentity.attachment.RoleAttachment;
import com.yygo.configentity.view.Role;
import com.yygo.configentity.view.RoleView;
import com.yygo.configentity.view.RoleViews;
import com.yygo.util.RoleViewConfigUtil;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by huanli on 2015/11/14.
 */
public class RoleViewsConfigurer {
    private RoleViews roleViews;

    public RoleView getPhase(String role, String phase) {
        List<Role> roleList = roleViews.getRoles().stream().filter((attachmentRole)-> attachmentRole.getName().equals(role)).collect(Collectors.toList());
        if (roleList.size()>0){
            List<RoleView> retViews = roleList.get(0).getRoleViews().stream().filter((roleView) -> roleView.getPhase().equals(phase)).collect(Collectors.toList());
            if(retViews.size()>0){
                return retViews.get(0);
            }
        }
        return null;
    }

    public void init() {
        roleViews = new RoleViewConfigUtil().read();
    }
}
